package SwingView;

import javax.swing.*;

import org.jdesktop.swingx.JXLabel;

import SwingView.CmsPageSelector.CmsPage;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/*-----------------------------------------------------------------------------
 * CLASS: CmsFeaturePanel
 * 
 * PURPOSE:
 * - Contain the Course Title Button. This button should load the name of the 
 * 	 current selected course and display as the title of the button. Clicking on
 *   this button should get the user to the home page of that course
 * - Contain a series of 7 feature buttons that let the user to select a feature
 *   to work with
 * - Contain the System Logo at the bottom of the Panel
 * 
 * CHANGE LOG:
 * @author Kim Do
 * @version v1 09/28/13 First version
 * 
 -----------------------------------------------------------------------------*/

public class CmsFeaturePanel extends JPanel{
	
	public static enum FeatureButtons{
		ANNOUNCEMENT,
		MESSAGE,
		LECTURE,
		ASSIGNMENT,
		QUIZ,
		GRADEBOOK,
		PEOPLE
	}
	

	private JTextArea jta;
	
	
	private JlCourseTitle jlCourseTitle;
	final private JButton jbtAnnouncements;
	final private JButton jbtMessages;
	final private JButton jbtLectures;
	final private JButton jbtAssignments;
	final private JButton jbtQuizzes;
	final private JButton jbtGradebook;
	final private JButton jbtPeople;
	
	final private JPanel jpButtonPanel;
	
	final private ImageIcon icSelectedAnnouncement = new ImageIcon("./assets/btnAnnouncements_Selected.png");
	final private ImageIcon icSelectedMessage = new ImageIcon("./assets/btnMessages_Selected.png");
	final private ImageIcon icSelectedLecture = new ImageIcon("./assets/btnLectures_Selected.png");
	final private ImageIcon icSelectedAssignment = new ImageIcon("./assets/btnAssignments_Selected.png");
	final private ImageIcon icSelectedQuiz = new ImageIcon("./assets/btnQuizzes_Selected.png");
	final private ImageIcon icSelectedGradebook = new ImageIcon("./assets/btnGradebook_Selected.png");
	final private ImageIcon icSelectedPeople = new ImageIcon("./assets/btnPeople_Selected.png");
	
	public CmsFeaturePanel(){

		//instantiate the buttons
		jlCourseTitle = new JlCourseTitle();
		jbtAnnouncements = new JButton();
		jbtAssignments = new JButton();
		jbtGradebook = new JButton();
		jbtLectures = new JButton();
		jbtMessages = new JButton();
		jbtPeople = new JButton();
		jbtQuizzes = new JButton();
		
		jta = new JTextArea();
		jta.setOpaque(false);
		jta.setForeground(Color.WHITE);
		jta.setLineWrap(true);
		jta.setWrapStyleWord(true);
		jta.setEditable(false);
		//jta.setPreferredSize(new Dimension(120,68));
		//jta.setText("default name for the course title and testing");
		jta.setFont(jta.getFont().deriveFont(17.0f).deriveFont(Font.BOLD));
		
		jlCourseTitle.add(jta,BorderLayout.CENTER);
		
		//set up roll-over icon for buttons
		setOriginalImageIconForButtons();
		setRollOverImageIconForButtons();
		
		//set the border for the button
		for(JButton button : this.retrieveListOfFeatureButtons()){
			button.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
		}
		
		//Add buttons to *HELPER PANEL 1*
		JPanel jpHelper1 = new JPanel();
		jpHelper1.setLayout(new GridLayout(7,1,0,0));
		jpHelper1.setOpaque(false);
		for(JButton button : this.retrieveListOfFeatureButtons()){
			jpHelper1.add(button);
		}
		
		//Add COURSE TITLE button and HELPER PANEL 1 to HELPER PANEL 2
		jpButtonPanel = new JPanel();
		jpButtonPanel.setLayout(new BorderLayout(0,0));
		jpButtonPanel.setOpaque(false);
		jpButtonPanel.add(jlCourseTitle,BorderLayout.NORTH);
		jpButtonPanel.add(jpHelper1,BorderLayout.SOUTH);
		jpButtonPanel.setPreferredSize(new Dimension(132,260));
		jpButtonPanel.setVisible(false);
		
		
		//Instantiate an Image Label for the logo
		JLabel jlLogo = new JLabel(new ImageIcon("./assets/imgLogo.png"));
		jlLogo.setBorder(BorderFactory.createEmptyBorder(15,18,15,18));
		
		//set up MAIN FEATURE PANEL
		setLayout(new BorderLayout(0,0));
		setOpaque(false);
		add(jpButtonPanel,BorderLayout.NORTH);
		add(jlLogo,BorderLayout.SOUTH);
	}
	
	//---------------------------------------------------------
	//HELPER METHODS
	//---------------------------------------------------------
	//Set original default image icon for buttons
	public void setOriginalImageIconForButtons(){
		jbtAnnouncements.setIcon(new ImageIcon("./assets/btnAnnouncements.png"));
		jbtMessages.setIcon(new ImageIcon("./assets/btnMessages.png"));
		jbtLectures.setIcon(new ImageIcon("./assets/btnLectures.png"));
		jbtAssignments.setIcon(new ImageIcon("./assets/btnAssignments.png"));
		jbtQuizzes.setIcon(new ImageIcon("./assets/btnQuizzes.png"));
		jbtGradebook.setIcon(new ImageIcon("./assets/btnGradebook.png"));
		jbtPeople.setIcon(new ImageIcon("./assets/btnPeople.png"));
	}
	
	//set roll-over default image icon for button
	public void setRollOverImageIconForButtons(){
		jbtAnnouncements.setRolloverIcon(new ImageIcon("./assets/btnAnnouncements_RO.png"));
		jbtMessages.setRolloverIcon(new ImageIcon("./assets/btnMessages_RO.png"));
		jbtLectures.setRolloverIcon(new ImageIcon("./assets/btnLectures_RO.png"));
		jbtAssignments.setRolloverIcon(new ImageIcon("./assets/btnAssignments_RO.png"));
		jbtQuizzes.setRolloverIcon(new ImageIcon("./assets/btnQuizzes_RO.png"));
		jbtGradebook.setRolloverIcon(new ImageIcon("./assets/btnGradebook_RO.png"));
		jbtPeople.setRolloverIcon(new ImageIcon("./assets/btnPeople_RO.png"));
	}
	
	public void setEnableAllButton(){
		jbtAnnouncements.setRolloverEnabled(true);
		jbtAssignments.setRolloverEnabled(true);
		jbtGradebook.setRolloverEnabled(true);
		jbtLectures.setRolloverEnabled(true);
		jbtMessages.setRolloverEnabled(true);
		jbtPeople.setRolloverEnabled(true);
		jbtQuizzes.setRolloverEnabled(true);
	}
	
	public void enableFeatureButtonPanel(){
		jpButtonPanel.setVisible(true);
	}
	
	public void disableFeatureButtonPanel(){
		jpButtonPanel.setVisible(false);
	}
	
	public void setCourseTitle(String courseTitle){
		jta.setText(courseTitle);
	}
	
	
	public void setSelectedButton(FeatureButtons button){
		
		switch(button){
		case ANNOUNCEMENT:
		{
			//jbtAnnouncements.setRolloverEnabled(false);
			jbtAnnouncements.setIcon(icSelectedAnnouncement);
			break;
		}
		case MESSAGE:
		{
			//this.jbtMessages.setRolloverEnabled(false);
			jbtMessages.setIcon(icSelectedMessage);
			break;
		}
		case QUIZ:
		{
			//this.jbtQuizzes.setRolloverEnabled(false);
			this.jbtQuizzes.setIcon(this.icSelectedQuiz);
			break;
		}
		case ASSIGNMENT:
		{
			//this.jbtAssignments.setRolloverEnabled(false);
			this.jbtAssignments.setIcon(this.icSelectedAssignment);
			break;
		}
		case PEOPLE:
		{
			//this.jbtPeople.setRolloverEnabled(false);
			this.jbtPeople.setIcon(this.icSelectedPeople);
			break;
		}
		case LECTURE:
		{
			//this.jbtLectures.setRolloverEnabled(false);
			this.jbtLectures.setIcon(this.icSelectedLecture);
			break;
		}
		case GRADEBOOK:
		{
			//this.jbtGradebook.setRolloverEnabled(false);
			this.jbtGradebook.setIcon(this.icSelectedGradebook);
			break;
		}
		}//end switch
		
		this.repaint();
	}
	
	//---------------------------------------------------------
	//NEW JBUTTON CLASS: JbtCourseTitle
	//	- specialized JButton for the course title
	//	- update button's text with the name of the selected course
	//---------------------------------------------------------
	public class JlCourseTitle extends JButton{

		public JlCourseTitle(){
			setOpaque(true);
			setBackground(Color.BLACK);
			setForeground(Color.WHITE);
			setBorder(BorderFactory.createEmptyBorder(7,7,7,7));
			this.setLayout(new BorderLayout());
			setPreferredSize(new Dimension(134,77));
		}
		
	}
	
	//---------------------------------------------------------
	//HELPER METHOD: Retrieve a list of the feature button
	//		* this excludes the Course Title Button
	//---------------------------------------------------------
	public ArrayList<JButton> retrieveListOfFeatureButtons(){
		ArrayList<JButton> buttonList = new ArrayList();
		
		buttonList.add(jbtAnnouncements);
		buttonList.add(jbtMessages);
		buttonList.add(jbtLectures);
		buttonList.add(jbtAssignments);
		buttonList.add(jbtQuizzes);
		buttonList.add(jbtGradebook);
		buttonList.add(jbtPeople);
		
		return buttonList;
	}
	
	
	//---------------------------------------------------------
	//GETTERS AND SETTERS:
	//---------------------------------------------------------
	public JButton getJbtAnnouncements() {
		return jbtAnnouncements;
	}

	public JlCourseTitle getJlCourseTitle() {
		return jlCourseTitle;
	}

	public void setJlCourseTitle(JlCourseTitle jlCourseTitle) {
		this.jlCourseTitle = jlCourseTitle;
	}

	public JButton getJbtMessages() {
		return jbtMessages;
	}

	public JButton getJbtLectures() {
		return jbtLectures;
	}

	public JButton getJbtAssignments() {
		return jbtAssignments;
	}

	public JButton getJbtQuizzes() {
		return jbtQuizzes;
	}

	public JButton getJbtGradebook() {
		return jbtGradebook;
	}

	public JButton getJbtPeople() {
		return jbtPeople;
	}
}
